package sg.edu.nus.iss.pacman.form;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

import sg.edu.nus.iss.pacman.midlet.PacManMIDlet;

/**
 * Form for Send Challenge Choice Form
 * 
 * @author Daniel
 *
 */
public class SendChallengeChoiceList extends List implements CommandListener {

	private static final String TITLE = "Send Challenge";
	private PacManMIDlet mainApp;
	
	private Command cmdBack;
	private Command cmdSelect;
	
	private String[] choices = new String[]{"Send via SMS", 
										  	"Send via Bluetooth"};
	
	/**
	 * Constructor for this screen
	 * 
	 * @param mainApp PacManMIDlet
	 */
	public SendChallengeChoiceList(PacManMIDlet mainApp) {
		super(TITLE, List.IMPLICIT, new String[]{}, null);		
		this.mainApp = mainApp;
		init();
	}
	
	/**
	 * Intializes the screen
	 */
	private void init() {
		cmdBack = new Command(PacManMIDlet.LABEL_CMD_BACK, Command.BACK, 1);
		cmdSelect = new Command(PacManMIDlet.LABEL_CMD_SELECT, Command.OK, 1);
		
		insert(0, choices[0], null);
		insert(1, choices[1], null);
		
		addCommand(cmdBack);
		addCommand(cmdSelect);
		setCommandListener(this);
	}
	
	/**
	 * This is a method which handles command actions
	 */
	public void commandAction(Command cmd, Displayable disp) {
		if (cmd == cmdBack) {
			mainApp.displayMainMenu();
		} else if (cmd == cmdSelect) {
			int idxSelected = getSelectedIndex();
			
			if (idxSelected == 0) {
				mainApp.displaySendChallengeViaSMS();
			} else if (idxSelected == 1) {
				mainApp.displaySendChallengeViaBluetooth();
			}
		}
	}
}
